<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="_fragments :: head(~{::title})">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客详情</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/semantic-ui/2.2.10/semantic.min.css">
    <link rel="stylesheet" href="../static/css/me.css"> <!--引入自定义CSS样式-->
    <link rel="stylesheet" href="../static/css/typo.css">
    <link rel="stylesheet" href="../static/css/animate.css">
    <link rel="stylesheet" href="../static/lib/prism/prism.css">
    <link rel="stylesheet" href="../static/lib/tocbot/tocbot.css">
</head>
<body>
    <!--导航-->
    <nav th:replace="_fragments :: menu(0)" class="ui inverted attached segment me-padded-tb-mini me-shadow-small"> <!--引入css样式-->
        <div class="ui container">
            <div class="ui inverted secondary menu stackable"><!--stackable可堆叠，解决手机访问-->
                <h2 class="ui teal header item">blog</h2> <!--item为menu中的一个条目-->
                <a href="#" class="m-item item me-mobile-hide"><i class="home icon"></i>首页</a><!--href为超链接-->
                <a href="#" class="m-item item me-mobile-hide"><i class="idea icon"></i>分类</a><!--m-item，在JQuery里获取样式-->
                <a href="#" class="m-item item me-mobile-hide"><i class="tags icon"></i>标签</a>
                <a href="#" class="m-item item me-mobile-hide"><i class="tags icon"></i>归档</a>
                <a href="#" class="m-item item me-mobile-hide"><i class="info icon"></i>关于我</a>
                <div class="right item">
                    <div class="ui icon input">
                        <label>
                            <input type="text" placeholder="Search...">
                        </label>
                        <i class="search link icon"></i>
                    </div>
                </div>
            </div>
        </div>
        <a href="#" class="ui black icon button me-top-right me-mobile-show menu toggle"> <!--手机端菜单图标, menu toggle获取点击事件-->            <i class="sidebar icon"></i>
        </a>
    </nav>

    <!--中间内容-->
    <div id="waypoint" class="me-container me-padded-tb-large ">
        <div class="container">
            <!--头部-->
            <div class="ui top attached segment"><!--上面是圆角，下面相连-->
                <div class="ui horizontal link list">
                    <div class="item"><!--图标？？-->
                        <img src="../static/images/girl.jpeg" th:src="@{${blog.user.avatar}}" alt="" class="ui avatar image"><!--avatar, 小图片-->
                        <div class="content">
                            <a href="#" class="header" th:src="@{${blog.user.nickname}}">泽宝宝</a>
                        </div>
                    </div>
                    <div class="item">
                        <i class="calendar icon"></i><span th:text="${#dates.format(blog.updateTime, 'yyyy-MM-dd')}">2020-05-24</span>
                    </div>
                    <div class="item">
                        <i class="eye icon" ></i><span th:text="${blog.views}">2342</span>
                    </div>
                </div>
            </div>

            <!--图片区域-->
            <div class="ui attached segment animated rubberBand">
                <img src="../static/images/girl.jpeg" th:src="@{${blog.firstPicture}}" alt="" class="ui fluid rounded image">
            </div>

            <!--内容-->
            <div class="ui attached segment padded">
                <div class="ui right aligned basic segment">
                    <div class="ui label basic orange" th:text="${blog.flag}">原创</div>
                </div>
                <h1 id="head" class="ui center aligned header" th:text="${blog.title}">设计模式详解</h1>
                <br>

                <!--content主要内容，需要把markdown转换成html-->
                <div id="blog-content" class="typo typo-selection js-toc-content me-padded-lr me-padded-tb" th:utext="${blog.content}"> <!--utext输出未转义html-->
                    <!--<textarea style="display: none" th:text="${blog.content}"></textarea>-->
                </div>
                <div class="me-padded-lr me-padded-tb">
                    <div class="ui basic teal left pointing label" th:each="tag: ${blog.tags}" th:text="${tag.name}">方法论</div>
                </div>

                <!--赞赏-->
                <div th:if="${blog.enableDonate}">
                    <div class="ui center aligned basic segment">
                        <button id="payButton" class="ui orange basic circular button">赞赏</button><!--circular加大圆角-->
                    </div>
                    <div class="ui payQR flowing popup top left transition hidden">
                        <div class="ui orange basic label">
                            <div class="ui images" style="font-size: inherit"><!--继承上级的字体（此处默认为0不显示）-->
                                <div class="ui rounded bordered image" style="width: 120px">
                                    <img src="../static/images/wechat.jpg" th:src="@{/images/alipay.jpg}" alt="">
                                    <div>支付宝支付</div>
                                </div>
                                <div class="ui rounded bordered image" style="width: 120px">
                                    <img src="../static/images/wechat.jpg" th:src="@{/images/wechatpay.png}" alt="">
                                    <div>微信支付</div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>


            </div>

            <!--信息-->
            <div class="ui attached positive message" th:if="${blog.enableShareStatement}"> <!--positive 变颜色-->
                <div class="ui middle aligned grid">
                    <div class="eleven wide column">
                        <ul class="list me-blue">
                            <li>作者：<span th:text="${blog.user.nickname}"></span><a href="#" target="_blank" th:href="@{/about}">（联系作者）</a></li>
                            <li>发表时间：<span th:text="${#dates.format(blog.updateTime, 'yyyy-MM-dd')}">2020-02-20</span></li>
                            <li>版权声明：自由转载-非商用</li>
                            <li>公众号转载：添加二维码</li>
                        </ul>
                    </div>
                    <div class="five wide column">
                        <!--right floated靠最右-->
                        <img src="../static/images/wechat.jpg" th:src="@{/images/wechat.jpg}" alt="" class="ui right floated rounded bordered image" style="width: 110px">
                    </div>
                </div>
            </div>

            <!--留言区域-->
            <div class="ui bottom attached segment me-margin-bottom-medium" th:if="${blog.enableComment}">
                <!--留言区域列表-->
                <div id="comment-container" class="ui teal segment">
                    <div th:fragment="commentList">
                        <div class="ui threaded comments" style="max-width: 100%">
                            <h3 class="ui dividing header">Comments</h3>
                            <div class="comment" th:each="comment: ${comments}">
                                <a class="avatar">
                                    <img style="width: 30px" src="../static/images/wechat.jpg" th:src="@{${comment.avatar}}">
                                </a>
                                <div class="content">
                                    <a class="author" >
                                        <span th:text="${comment.nickname}">Matt</span>
                                        <!--没有is，命名规则-->
                                        <div class="ui mini basic teal left pointing label me-padded-small" th:if="${comment.adminComment}">博主</div>
                                    </a>
                                    <div class="metadata">
                                        <span class="date" th:text="${#dates.format(comment.createTime, 'yyyy-MM-dd HH:mm')}">Today at 5:42PM</span>
                                    </div>
                                    <div class="text" th:text="${comment.content}">
                                        How artistic!
                                    </div>
                                    <div class="actions">
                                        <!--自定义属性，拿到本次评论的id和nickname，作为下次的父评论-->
                                        <a class="reply" data-commentid="1"
                                           th:attr="data-commentid=${comment.id},
                                           data-commentnickname=${comment.nickname}"
                                           data-commentnickname="Matt"
                                           onclick="reply(this)">回复</a>
                                    </div>
                                </div>
                                <div class="comments" th:if="${#arrays.length(comment.replyComments)>0}">
                                    <div class="comment" th:each="reply: ${comment.replyComments}">
                                        <a class="avatar">
                                            <img style="width: 30px" src="../static/images/wechat.jpg" th:src="@{${reply.avatar}}">
                                        </a>
                                        <div class="content">
                                            <a class="author">
                                                <span th:text="${reply.nickname}">Matt</span>
                                                <div class="ui mini basic teal left pointing label me-padded-small" th:if="${reply.adminComment}">博主</div>
                                                &nbsp;<span class="me-blue" th:text="|@${reply.parentComment.nickname}|">@ jojo</span>
                                            </a>
                                            <div class="metadata">
                                                <span class="date" th:text="${#dates.format(reply.createTime, 'yyyy-MM-dd HH:mm')}">Today at 5:42PM</span>
                                            </div>
                                            <div class="text" th:text="${reply.content}">
                                                How artistic!
                                            </div>
                                            <div class="actions">
                                                <!--自定义属性，拿到本次评论的id和nickname，作为下次的父评论-->
                                                <a class="reply" data-commentid="1"
                                                   th:attr="data-commentid=${reply.id},
                                           data-commentnickname=${reply.nickname}"
                                                   data-commentnickname="Matt"
                                                   onclick="reply(this)">回复</a>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <!--/*-->
                            <div class="comment">
                                <a class="avatar">
                                    <img src="../static/images/wechat.jpg">
                                </a>
                                <div class="content">
                                    <a class="author">Elliot Fu</a>
                                    <div class="metadata">
                                        <span class="date">Yesterday at 12:30AM</span>
                                    </div>
                                    <div class="text">
                                        <p>This has been very useful for my research. Thanks as well!</p>
                                    </div>
                                    <div class="actions">
                                        <a class="reply">Reply</a>
                                    </div>
                                </div>
                                <div class="comments">
                                    <div class="comment">
                                        <a class="avatar">
                                            <img src="../static/images/wechat.jpg">
                                        </a>
                                        <div class="content">
                                            <a class="author">Jenny Hess</a>
                                            <div class="metadata">
                                                <span class="date">Just now</span>
                                            </div>
                                            <div class="text">
                                                Elliot you are always so right :)
                                            </div>
                                            <div class="actions">
                                                <a class="reply">Reply</a>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="comment">
                                <a class="avatar">
                                    <img src="../static/images/wechat.jpg">
                                </a>
                                <div class="content">
                                    <a class="author">Joe Henderson</a>
                                    <div class="metadata">
                                        <span class="date">5 days ago</span>
                                    </div>
                                    <div class="text">
                                        Dude, this is awesome. Thanks so much
                                    </div>
                                    <div class="actions">
                                        <a class="reply">Reply</a>
                                    </div>
                                </div>
                            </div>
                            <!--*/-->
                        </div>
                    </div>
                </div>

                <!--提交留言区域-->
                <div class="ui blue segment">
                    <div id="comment-form" class="ui reply form">
                        <!--隐含域，用户不可见但必须提交-->
                        <input type="hidden" name="blog.id" th:value="${blog.id}">
                        <input type="hidden" name="parentComment.id" value="-1">

                        <div class="required field">
                            <textarea name="content" placeholder="请输入评论信息"></textarea>
                        </div>
                        <div class="fields">
                            <div class="required field me-mobile-wide me-margin-bottom-tiny">
                                <div class="ui left icon input">
                                    <i class="user icon"></i>
                                    <input type="text" name="nickname" placeholder="用户" th:value="${session.user}!=null ? ${session.user.nickname}">
                                </div>
                            </div>
                            <div class="required field me-mobile-wide me-margin-bottom-tiny">
                                <div class="ui left icon input">
                                    <i class="mail icon"></i>
                                    <input type="text" name="email" placeholder="邮箱" th:value="${session.user}!=null ? ${session.user.email}">
                                </div>
                            </div>
                            <!--两个都加wide才能手机端充满-->
                            <div class="field me-mobile-wide">
                                <!--button类型不会提交表单-->
                                <button type="button" id="commentpost-btn" class="ui blue labeled submit icon me-mobile-wide button">
                                    <i class="icon edit"></i>提交评论
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!--工具条--><!--使用绝对布局-->
    <div id="toolbar" class="me-right-bottom me-fixed me-padded-large" style="display: none">
        <div class="ui vertical icon buttons">
            <button type="button" class="ui toc teal button">目录</button>
            <a href="#comment-container" type="button" class="ui teal button">留言</a><!--#id，超链接到-->
            <button type="button" class="ui wechat button"><i class="weixin icon"></i></button><!--扫码阅读-->
            <div id="toTop-button" class="ui button"><i class="chevron up icon"></i></div><!--#回到顶部-->
        </div>
    </div>

    <div class="ui toc-container flowing popup transition hidden" style="width: 200px">
        <ol class="js-toc"></ol>
    </div>

    <div id="qrcode" class="ui wechat-QR flowing popup top left transition hidden" style="width: 130px !important;">
<!--        <img src="./static/images/wechat.jpg" alt="" class="ui rounded image" style="width: 100px !important;">-->
    </div>

    <!--底部footer-->
    <footer th:replace="_fragments :: footer" class="ui inverted vertical segment me-padded-tb-max"><!--vertical消除圆角，用attached好像也行-->
        <div class="ui center aligned container"><!--居中-->
            <div class="ui inverted divided grid stackable"><!--grid stackable默认均匀分成16份, divided分割线-->
                <div class="three wide column">
                    <div class="ui inverted link list">
                        <div class="item">
                            <img src="../static/images/wechat.jpg" class="ui rounded image" alt="" style="width: 110px"><!--alt规定图片无法显示时的替代文本-->
                        </div>
                    </div>
                </div>
                <div class="three wide column">
                    <h4 class="ui inverted header me-text-space me-opacity-mini">最新博客</h4><!--标题-->
                    <div class="ui inverted link list">
                        <a href="#" class="item me-text-thin me-text-lined">用户故事</a>
                        <a href="#" class="item me-text-thin me-text-lined">用户故事</a>
                        <a href="#" class="item me-text-thin me-text-lined">用户故事</a>
                    </div>
                </div>
                <div class="three wide column">
                    <h4 class="ui inverted header me-text-space me-opacity-mini">联系我</h4><!--标题-->
                    <div class="ui inverted link list">
                        <a href="#" class="item me-text-thin me-text-lined">Email: stg1205@163.com</a>
                        <a href="#" class="item me-text-thin me-text-lined">QQ: 1014922487</a>
                    </div>
                </div>
                <div class="seven wide column">
                    <h4 class="ui inverted header me-text-space me-opacity-mini">介绍</h4>
                    <p class="me-text-space me-text-thin me-text-lined me-opacity-mini">这是我的个人博客，啦啦啦啦啦啦拉拉拉啊拉啦阿拉</p>
                </div>
            </div>
            <div class="ui inverted section divider"></div>
            <p class="me-text-space me-opacity-tiny">Copyright</p>
        </div>

    </footer>
    <th:block th:replace="_fragments :: script"></th:block>
    <script src="https://cdn.jsdelivr.net/npm/jquery.scrollto@2.1.2/jquery.scrollTo.min.js"></script>
    <script src="../static/lib/prism/prism.js" th:src="@{/lib/prism/prism.js}"></script><!--代码高亮-->
    <script src="../static/lib/tocbot/tocbot.min.js" th:src="@{/lib/tocbot/tocbot.min.js}"></script><!--目录生成-->
    <script src="../static/lib/qrcode/qrcode.min.js" th:src="@{/lib/qrcode/qrcode.min.js}"></script>
    <script src="../static/lib/waypoints/jquery.waypoints.min.js" th:src="@{/lib/waypoints/jquery.waypoints.min.js}"></script>
    <!--<script th:src="@{/lib/editor/lib/marked.min.js}"></script>
    <script th:src="@{/lib/editor/lib/prettify.min.js}"></script>
    <script th:src="@{/lib/editor/lib/raphael.min.js}"></script>
    <script th:src="@{/lib/editor/lib/underscore.min.js}"></script>
    <script th:src="@{/lib/editor/lib/sequence-diagram.min.js}"></script>
    <script th:src="@{/lib/editor/lib/flowchart.min.js}"></script>
    <script th:src="@{/lib/editor/lib/jquery.flowchart.min.js}"></script>
    <script th:src="@{/lib/editor/editormd.js}"></script>
    <script type="text/javascript">
        editormd.markdownToHTML("blog-content", {
            htmlDecode      : "style,script,iframe",  // you can filter tags decode
            emoji           : true,
            taskList        : true,
            tex             : true,  // 默认不解析
            flowChart       : true,  // 默认不解析
            sequenceDiagram : true,  // 默认不解析
        });
    </script>-->

    <script th:inline="javascript"> /*下面是用thymeleaf模板就得加*/
        $('.menu.toggle').click(function () {
            $('.m-item').toggleClass('me-mobile-hide');/*toggleClass，取反函数*/
        });

        $('#payButton').popup({//二维码pop up
            popup: $('.payQR.popup'),
            on: 'click',
            position: 'bottom center'
        });

        $('.wechat').popup({
            popup: $('.wechat-QR.popup'),
            position: 'left center'
        });

        //多了就有问题 显示不全
        $('.toc').popup({//目录pop up
            popup: $('.toc-container'),
            on: 'click',
            position: 'top center'
        });

        /*目录初始化，指定生成位置，来源以及标签样式*/
        tocbot.init({
            //where to render the table of contents
            tocSelector: '.js-toc',
            //where to grab the headings to build the table of contents
            contentSelector: '.js-toc-content',
            //which headings to grab inside of the contentSelector element
            headingSelector: 'h1, h2, h3',
        });

        /*QR初始化*/
        var serverurl = "39.96.83.145";
        var url = /*[[@{/blog/{id}(id=${blog.id})}]]*/""; //用thymeleaf模板获取
        var qrcode = new QRCode("qrcode", {
            text: serverurl + url,
            width: 100,
            height: 100,
            colorDark : "#000000",
            colorLight : "#ffffff",
            correctLevel : QRCode.CorrectLevel.H
        });

        /*滚动动画*/
        $('#toTop-button').click(function () {
            $(window).scrollTo(0, 500) /*设置滚动时间*/
        });

        /*waypoints实现滚动检测*/
        var waypoint = new Waypoint({
            element: document.getElementById('waypoint'),
            handler: function(direction) {
                if (direction === 'down') {
                    $('#toolbar').show(500);
                } else {
                    $('#toolbar').hide(500);
                }
                console.log('Scrolled to waypoint!' + direction)
            }
        });

        /*表单验证*/
        $('.ui.form').form({
            fields: { //要加s。。。
                content: {
                    identifier: 'content',//与name一致
                    rules: [{
                        type: 'empty',
                        prompt: '请输入评论内容', //提示内容
                    }]
                },
                nickname: {
                    identifier: 'nickname',//与name一致
                    rules: [{
                        type: 'empty',
                        prompt: '请输入用户名', //提示内容
                    }]
                },
                email: {
                    identifier: 'email',//与name一致
                    rules: [{
                        type: 'email',
                        prompt: '请输入正确邮箱地址', //提示内容
                    }]
                }
            }
        });

        $('#commentpost-btn').click(function () {
            var boo = $('.ui.form').form('validate form');
            if (boo) {
                console.log('校验成功');
                postData();
            } else {
                console.log('校验失败');
            }
        });

        function postData() {
            // 提交到哪里，提交哪些东西
            $("#comment-container").load(/*[[@{/comments}]]*/"",{
                "parentComment.id" : $("[name='parentComment.id']").val(),
                "blog.id" : $("[name='blog.id']").val(),
                "nickname": $("[name='nickname']").val(),
                "email"   : $("[name='email']").val(),
                "content" : $("[name='content']").val()
            },function (responseTxt, statusTxt, xhr) {
                //$(window).scrollTo($('#comment-container'),500); //滚动到哪里，时间间隔
                clearContent();
            });
        }

        function clearContent() {
            $("[name='content']").val('');
            $("[name='parentComment.id']").val(-1);
            $("[name='content']").attr("placeholder", "请输入评论信息");
        }

        function reply(obj) {
            /*data方法大写获取不到值所以不用驼峰命名法*/
            var commentId = $(obj).data('commentid'); //使用data方法只需要写后缀
            var commentNickname = $(obj).data('commentnickname');
            $("[name='content']").attr("placeholder", "@" + commentNickname).focus();
            $("[name='parentComment.id']").val(commentId);
            $(window).scrollTo($('#comment-form'),500); //滚动到哪里，时间间隔
        }

        /*单独访问页面的时候评论没有load*/
        $(function () {
            $("#comment-container").load(/*[[@{/comments/{id}(id=${blog.id})}]]*/"");
        });

        //要加后面的""里的地址
        $('#newBlog-container').load(/*[[@{/footer/newBlogs}]]*/"/footer/newBlogs");
    </script>
</body>
</html>